﻿using Microsoft.EntityFrameworkCore.Migrations;
using System;
using System.Collections.Generic;

namespace SaiLing.SingleSignOn.Repository.Migrations
{
    public partial class init_database : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "SaiLing_System_Account",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    Email = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    IsAdministrator = table.Column<bool>(type: "bit", nullable: false),
                    IsAppAdministrator = table.Column<bool>(type: "bit", nullable: false),
                    IsApproved = table.Column<bool>(type: "bit", nullable: false),
                    IsLockedOut = table.Column<bool>(type: "bit", nullable: false),
                    LastLockoutDate = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastLoginDate = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastPasswordChangedDate = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LogicRemove = table.Column<bool>(type: "bit", nullable: false),
                    LoginName = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    Name = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    Password = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    PasswordSalt = table.Column<string>(type: "nvarchar(max)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SaiLing_System_Account", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "SaiLing_System_Application",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    AppKey = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    AppSecret = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    Icon = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    LogicRemove = table.Column<bool>(type: "bit", nullable: false),
                    Name = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    Remark = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    Url = table.Column<string>(type: "nvarchar(max)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SaiLing_System_Application", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "SaiLing_System_OperationLog",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    Ip = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    LogType = table.Column<int>(type: "int", nullable: false),
                    LogicRemove = table.Column<bool>(type: "bit", nullable: false),
                    OperatorContent = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    OperatorRemark = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    OperatorType = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    UserId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    UserName = table.Column<string>(type: "nvarchar(max)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SaiLing_System_OperationLog", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "SaiLing_System_Organization",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    FullName = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    LogicRemove = table.Column<bool>(type: "bit", nullable: false),
                    ParentId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    ShortName = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    Sort = table.Column<int>(type: "int", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SaiLing_System_Organization", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "SaiLing_System_Module",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    AppId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    Area = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    Background = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    ExecAction = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ExecController = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    Icon = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    LogicRemove = table.Column<bool>(type: "bit", nullable: false),
                    ModuleId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    Name = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ParentId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    Sort = table.Column<int>(type: "int", nullable: false),
                    Visible = table.Column<bool>(type: "bit", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SaiLing_System_Module", x => x.Id);
                    table.ForeignKey(
                        name: "FK_SaiLing_System_Module_SaiLing_System_Application_AppId",
                        column: x => x.AppId,
                        principalTable: "SaiLing_System_Application",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_SaiLing_System_Module_SaiLing_System_Module_ModuleId",
                        column: x => x.ModuleId,
                        principalTable: "SaiLing_System_Module",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "SaiLing_System_Position",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    FullName = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    IsManage = table.Column<bool>(type: "bit", nullable: false),
                    LogicRemove = table.Column<bool>(type: "bit", nullable: false),
                    OrganizationId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    ShortName = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    Sort = table.Column<int>(type: "int", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SaiLing_System_Position", x => x.Id);
                    table.ForeignKey(
                        name: "FK_SaiLing_System_Position_SaiLing_System_Organization_OrganizationId",
                        column: x => x.OrganizationId,
                        principalTable: "SaiLing_System_Organization",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "SaiLing_System_ModuleAction",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    LogicRemove = table.Column<bool>(type: "bit", nullable: false),
                    ModuleId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    Name = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    Sort = table.Column<int>(type: "int", nullable: false),
                    Url = table.Column<string>(type: "nvarchar(max)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SaiLing_System_ModuleAction", x => x.Id);
                    table.ForeignKey(
                        name: "FK_SaiLing_System_ModuleAction_SaiLing_System_Module_ModuleId",
                        column: x => x.ModuleId,
                        principalTable: "SaiLing_System_Module",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "SaiLing_System_OrganizationMenuAuthority",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    Appid = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    ModuleActionId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    ModuleId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    OrganizationId = table.Column<Guid>(type: "uniqueidentifier", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SaiLing_System_OrganizationMenuAuthority", x => x.Id);
                    table.ForeignKey(
                        name: "FK_SaiLing_System_OrganizationMenuAuthority_SaiLing_System_Application_Appid",
                        column: x => x.Appid,
                        principalTable: "SaiLing_System_Application",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_SaiLing_System_OrganizationMenuAuthority_SaiLing_System_ModuleAction_ModuleActionId",
                        column: x => x.ModuleActionId,
                        principalTable: "SaiLing_System_ModuleAction",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.NoAction);
                    table.ForeignKey(
                        name: "FK_SaiLing_System_OrganizationMenuAuthority_SaiLing_System_Module_ModuleId",
                        column: x => x.ModuleId,
                        principalTable: "SaiLing_System_Module",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.NoAction);
                    table.ForeignKey(
                        name: "FK_SaiLing_System_OrganizationMenuAuthority_SaiLing_System_Organization_OrganizationId",
                        column: x => x.OrganizationId,
                        principalTable: "SaiLing_System_Organization",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_SaiLing_System_Module_AppId",
                table: "SaiLing_System_Module",
                column: "AppId");

            migrationBuilder.CreateIndex(
                name: "IX_SaiLing_System_Module_ModuleId",
                table: "SaiLing_System_Module",
                column: "ModuleId");

            migrationBuilder.CreateIndex(
                name: "IX_SaiLing_System_ModuleAction_ModuleId",
                table: "SaiLing_System_ModuleAction",
                column: "ModuleId");

            migrationBuilder.CreateIndex(
                name: "IX_SaiLing_System_OrganizationMenuAuthority_Appid",
                table: "SaiLing_System_OrganizationMenuAuthority",
                column: "Appid");

            migrationBuilder.CreateIndex(
                name: "IX_SaiLing_System_OrganizationMenuAuthority_ModuleActionId",
                table: "SaiLing_System_OrganizationMenuAuthority",
                column: "ModuleActionId");

            migrationBuilder.CreateIndex(
                name: "IX_SaiLing_System_OrganizationMenuAuthority_ModuleId",
                table: "SaiLing_System_OrganizationMenuAuthority",
                column: "ModuleId");

            migrationBuilder.CreateIndex(
                name: "IX_SaiLing_System_OrganizationMenuAuthority_OrganizationId",
                table: "SaiLing_System_OrganizationMenuAuthority",
                column: "OrganizationId");

            migrationBuilder.CreateIndex(
                name: "IX_SaiLing_System_Position_OrganizationId",
                table: "SaiLing_System_Position",
                column: "OrganizationId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "SaiLing_System_Account");

            migrationBuilder.DropTable(
                name: "SaiLing_System_OperationLog");

            migrationBuilder.DropTable(
                name: "SaiLing_System_OrganizationMenuAuthority");

            migrationBuilder.DropTable(
                name: "SaiLing_System_Position");

            migrationBuilder.DropTable(
                name: "SaiLing_System_ModuleAction");

            migrationBuilder.DropTable(
                name: "SaiLing_System_Organization");

            migrationBuilder.DropTable(
                name: "SaiLing_System_Module");

            migrationBuilder.DropTable(
                name: "SaiLing_System_Application");
        }
    }
}
